//
//  MoreViewController.m
//  LiveDailyNews
//
//  Created by smu on 11-7-19.
//  Copyright 2011年 duk. All rights reserved.
//

#import "MoreViewController.h"
#import "MoreShowController.h"
#import "Constant.h"


@implementation MoreViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.tabBarItem.title = @"更多";
		self.tabBarItem.image = [UIImage imageNamed:@"TAB_ICON_MENU.png"];
        
        //导航栏添加内容
        //左边logo
        UIImage *logoImage = [[UIImage alloc] initWithContentsOfFile:[
                                                                      [[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Logo.png"]];
        UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 32)];  
        logoImageView.image = logoImage;
        [logoImage release];
        UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:logoImageView]; 
        [logoImageView release];
        self.navigationItem.leftBarButtonItem = leftBarButton;
        [leftBarButton release];
        
        //中间标题
        self.navigationItem.title = @"更多";
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    //获取整个手机屏幕
    UIView *contentView = [[[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame] autorelease];
	
	contentView.autoresizesSubviews = YES;
	self.view = contentView;
	[self.view setBackgroundColor:[UIColor clearColor]];
    /*    
     CGRect frame = contentView.frame;
     frame.origin.x = 0;
     frame.origin.y = contentView.bounds.size.height - frame.size.height+25;
     frame.size.width = contentView.bounds.size.width;
     frame.size.height = contentView.bounds.size.height - 44 - 48-25;
     */	
	mtableView = [[UITableView alloc] initWithFrame:
                  CGRectMake(0, 0, contentView.bounds.size.width, contentView.bounds.size.height - 44 - 48) style:UITableViewCellStyleDefault];
	mtableView.delegate = self;
	mtableView.dataSource = self;
	mtableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
	mtableView.scrollEnabled = YES;
	[mtableView setBackgroundColor:[UIColor clearColor]];
    
	[self.view addSubview:mtableView];
    
    
    //test tableView
    moreItem = [[NSArray alloc] initWithObjects:@"汽车",@"房产",@"书评",@"关于",@"版权", nil];
    moreImageName = [[NSArray alloc] initWithObjects:@"book.png",@"about.png",@"book.png",@"about.png",@"copyrights.png", nil];
    moreLink = [[NSArray alloc] initWithObjects:ABOUT ,COPYRIGHT,ABOUT,COPYRIGHT,ABOUT, nil];
    
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [moreItem count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *moreTableIdentifier = @"MoreTableIdentifier";
    NSUInteger row = [indexPath row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:moreTableIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
                 initWithStyle:UITableViewCellStyleDefault
                 reuseIdentifier:moreTableIdentifier] autorelease];
    }
    UIImage *image = [UIImage imageNamed:[moreImageName objectAtIndex:row]];
    cell.imageView.image = image;
    cell.textLabel.text = [moreItem objectAtIndex: row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:[moreLink objectAtIndex:row] forKey:@"moreLink"];
    MoreShowController *moreShow = [[MoreShowController alloc] init];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:moreShow animated:YES];
    self.hidesBottomBarWhenPushed = NO;;
    
    
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 50;
//}

@end
